/**
 * Title: RestResult.java
 * @author wujin
 * @date 2019年12月30日
 * @version 1.0
 */
package com.pm.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.pm.common.exception.ExpCodeState;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * 
 * 接口统一返回结果 Title: RestResult
 * 
 * @author WuJin
 * @date 2019年12月30日
 */
@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModel
public class Response<T> {
	private static final Integer successCode = 200;
	@ApiModelProperty(value = "")
	private Integer code;// 结果编码
	@ApiModelProperty(value = "")
	private String msg;// 内容
	@ApiModelProperty(value = "")
	private T data;// 数据

	public Response() {
		this.code = successCode;
		this.msg = "请求成功";
	}

	public Response(Integer code, String msg) {
		this();
		this.code = code;
		this.msg = msg;
	}

	public Response(ExpCodeState exp, T result) {
		this();
		this.code = exp.getCode();
		this.msg = exp.getMsg();
		this.data = result;
	}

	public Response(ExpCodeState exp) {
		this();
		this.code = exp.getCode();
		this.msg = exp.getMsg();
	}

	public Response(Integer code, String msg, T data) {
		this();
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	public Response(T data) {
		this();
		this.data = data;
	}

	public void setExpInfo(ExpCodeState exp) {
		this.code = exp.getCode();
		this.msg = exp.getMsg();
	}

	public static Integer getSuccessCode() {
		return successCode;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}
}
